package com.cloud.service;
 
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.cloud.entity.SysRole;
import com.cloud.entity.SysUser;
import com.cloud.mapper.SysRoleMapper;
import com.cloud.mapper.SysUserMapper;
 
@Service
public class UserService implements UserDetailsService {
    @Autowired
    SysUserMapper sysUserMapper;  
    
    @Autowired
    SysRoleMapper roleMapper;
 
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    	SysUser user =sysUserMapper.selectUserByUsername(username);
        if(null == user){
            throw new UsernameNotFoundException("没有此用户");
        }
        List<SysRole> roles = roleMapper.selectUserByUserId(user.getUserId());
        user.setRoles(roles);
        return user;
    }
}